#include <iostream>
#include <vector>
#include <memory.h>
#include <cmath>
using namespace std;

bool vis[200005];
vector<int> G[200005];
int ans, ai;

void dfs(int x, int w) {
	if (vis[x]) return;
	vis[x] = 1;
	if (w > ans) {
		ans = w;
		ai = x;
	}

	for (unsigned i = 0; i < G[x].size(); ++i) {
		dfs(G[x][i], w + 1);
	}
}

int calc(int w) {
	if (w % 3 <= 1) {
		return w / 3;
	} else {
		return w / 3 + 1;
	}
}

int main() {
	int T;
	cin >> T;
	while (T--) {
		int n, x, y;
		cin >> n;

		for (int i = 1; i < n; ++i) {
			cin >> x >> y;
			G[x].push_back(y);
			G[y].push_back(x);
		}

		ans = -1;
		memset(vis, 0, sizeof(vis));
		dfs(1, 0);

		ans = -1;
		memset(vis, 0, sizeof(vis));
		dfs(ai, 0);

		cout << calc(ans) << endl;

		for (int i = 0; i <= n; ++i) {
			G[i].clear();
		}
	}


	return 0;
}